Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

behavioral pattern (state) #204

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

timsoriano3
Copy link

Implemented the behavioral design pattern 'State' contained in new file created named 'webscraper_state_pattern.py'. This pattern integrates with the file 'webscraper.py' for the methods connect() and save_to_db() because these methods follow a specific order.

Since these 2 methods are sequential, i.e. the method connect() must be called before the method save_to_db(), the state pattern can instead assign states of the program that tells you the current state whether it is in state where connect() must be called (ConcreteConnectState()) or in the state where save_to_db() bust be called (ConcreteSaveState()).

This improves the system design by removing redundancies in the method implementations as well creating an abstraction for the method implementations which makes the code less complex. Another benefit of this design is that this pattern can now also be used by other files in the code base that deals with methods connect() and / or save_to_db() such as the file 'db_connector.py' in the same directory.

This design also emphasizes using the state transitions that create a sequence such that when the program is at a certain state, the program can only execute specific methods that adhere to the corresponding state. This makes the structure of the code much cleaner and more efficient both in space as well as time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant